Skip to content

Conversation

@Hweinstock
Copy link
Contributor

@Hweinstock Hweinstock commented Nov 21, 2024

Problem

The test logger does not format additional arguements into the logs in the same way as ToolkitLogger.
Ex. getLogger().debug('here is the obj: %O', obj) will produce two LogEntries one with "here is the obj: %O" and one with the object itself.

This is problematic because it causes confusion (see: #5895 (comment)) and it also can cause assertLogsContain to throw an error since there is now a non-string/error entry in the log entry list (see:

export function assertLogsContain(text: string, exactMatch: boolean, severity: LogLevel) {
const logs = getTestLogger().getLoggedEntries(severity)
assert.ok(
logs.some((e) =>
e instanceof Error
? exactMatch
? e.message === text
: e.message.includes(text)
: exactMatch
? e === text
: e.includes(text)
),
`Expected to find "${text}" in the logs as type "${severity}"`
)
}
).

Solution


License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

})
})

it('assigns schemas to the yaml extension', async function () {
Copy link
Contributor Author

@Hweinstock Hweinstock Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when passing some objects through util.format I noticed it set a property _formatted (perhaps as a cache?), so without these changes the test fails. Also avoids some small code dupe.

@Hweinstock Hweinstock marked this pull request as ready for review November 22, 2024 15:44
@Hweinstock Hweinstock requested a review from a team as a code owner November 22, 2024 15:44
* In-memory Logger implementation suitable for use by tests.
*/
export class TestLogger implements Logger {
export class TestLogger extends BaseLogger {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, was just thinking about this!

Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@justinmk3 justinmk3 merged commit 2b6987a into aws:master Nov 22, 2024
32 of 35 checks passed
@Hweinstock Hweinstock deleted the fixTestLogger branch November 22, 2024 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants